/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.pku.sei.AMT.impl;

import edu.pku.sei.AMT.AmtPackage;
import edu.pku.sei.AMT.LinkConstraint;
import edu.pku.sei.AMT.Section;
import edu.pku.sei.AMT.Variable;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Section</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link edu.pku.sei.AMT.impl.SectionImpl#getReferredVariables <em>Referred Variables</em>}</li>
 *   <li>{@link edu.pku.sei.AMT.impl.SectionImpl#getLinks <em>Links</em>}</li>
 *   <li>{@link edu.pku.sei.AMT.impl.SectionImpl#getExpressions <em>Expressions</em>}</li>
 *   <li>{@link edu.pku.sei.AMT.impl.SectionImpl#getSections <em>Sections</em>}</li>
 *   <li>{@link edu.pku.sei.AMT.impl.SectionImpl#getModelName <em>Model Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SectionImpl extends ModifierElementImpl implements Section {
	/**
	 * The cached value of the '{@link #getReferredVariables() <em>Referred Variables</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferredVariables()
	 * @generated
	 * @ordered
	 */
	protected EList referredVariables;

	/**
	 * The cached value of the '{@link #getLinks() <em>Links</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLinks()
	 * @generated
	 * @ordered
	 */
	protected EList links;

	/**
	 * The cached value of the '{@link #getExpressions() <em>Expressions</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExpressions()
	 * @generated
	 * @ordered
	 */
	protected EList expressions;

	/**
	 * The cached value of the '{@link #getSections() <em>Sections</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSections()
	 * @generated
	 * @ordered
	 */
	protected EList sections;

	/**
	 * The default value of the '{@link #getModelName() <em>Model Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModelName()
	 * @generated
	 * @ordered
	 */
	protected static final String MODEL_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getModelName() <em>Model Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModelName()
	 * @generated
	 * @ordered
	 */
	protected String modelName = MODEL_NAME_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SectionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return AmtPackage.Literals.SECTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getReferredVariables() {
		if (referredVariables == null) {
			referredVariables = new EObjectResolvingEList(Variable.class, this, AmtPackage.SECTION__REFERRED_VARIABLES);
		}
		return referredVariables;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getLinks() {
		if (links == null) {
			links = new EObjectContainmentEList(LinkConstraint.class, this, AmtPackage.SECTION__LINKS);
		}
		return links;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getExpressions() {
		if (expressions == null) {
			expressions = new EDataTypeUniqueEList(String.class, this, AmtPackage.SECTION__EXPRESSIONS);
		}
		return expressions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getSections() {
		if (sections == null) {
			sections = new EObjectContainmentEList(Section.class, this, AmtPackage.SECTION__SECTIONS);
		}
		return sections;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getModelName() {
		return modelName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setModelName(String newModelName) {
		String oldModelName = modelName;
		modelName = newModelName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AmtPackage.SECTION__MODEL_NAME, oldModelName, modelName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public EList getSectionsByModifiers(EList modifiers) {
		EList result = new BasicEList();
		for(Object r : getSections()) {
			Section s = (Section)r;
			if(s.getModifiers().containsAll(modifiers))
				result.add(s);
		}
		
		return result;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case AmtPackage.SECTION__LINKS:
				return ((InternalEList)getLinks()).basicRemove(otherEnd, msgs);
			case AmtPackage.SECTION__SECTIONS:
				return ((InternalEList)getSections()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case AmtPackage.SECTION__REFERRED_VARIABLES:
				return getReferredVariables();
			case AmtPackage.SECTION__LINKS:
				return getLinks();
			case AmtPackage.SECTION__EXPRESSIONS:
				return getExpressions();
			case AmtPackage.SECTION__SECTIONS:
				return getSections();
			case AmtPackage.SECTION__MODEL_NAME:
				return getModelName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case AmtPackage.SECTION__REFERRED_VARIABLES:
				getReferredVariables().clear();
				getReferredVariables().addAll((Collection)newValue);
				return;
			case AmtPackage.SECTION__LINKS:
				getLinks().clear();
				getLinks().addAll((Collection)newValue);
				return;
			case AmtPackage.SECTION__EXPRESSIONS:
				getExpressions().clear();
				getExpressions().addAll((Collection)newValue);
				return;
			case AmtPackage.SECTION__SECTIONS:
				getSections().clear();
				getSections().addAll((Collection)newValue);
				return;
			case AmtPackage.SECTION__MODEL_NAME:
				setModelName((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
			case AmtPackage.SECTION__REFERRED_VARIABLES:
				getReferredVariables().clear();
				return;
			case AmtPackage.SECTION__LINKS:
				getLinks().clear();
				return;
			case AmtPackage.SECTION__EXPRESSIONS:
				getExpressions().clear();
				return;
			case AmtPackage.SECTION__SECTIONS:
				getSections().clear();
				return;
			case AmtPackage.SECTION__MODEL_NAME:
				setModelName(MODEL_NAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case AmtPackage.SECTION__REFERRED_VARIABLES:
				return referredVariables != null && !referredVariables.isEmpty();
			case AmtPackage.SECTION__LINKS:
				return links != null && !links.isEmpty();
			case AmtPackage.SECTION__EXPRESSIONS:
				return expressions != null && !expressions.isEmpty();
			case AmtPackage.SECTION__SECTIONS:
				return sections != null && !sections.isEmpty();
			case AmtPackage.SECTION__MODEL_NAME:
				return MODEL_NAME_EDEFAULT == null ? modelName != null : !MODEL_NAME_EDEFAULT.equals(modelName);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (expressions: ");
		result.append(expressions);
		result.append(", modelName: ");
		result.append(modelName);
		result.append(')');
		return result.toString();
	}

} //SectionImpl
